import {
  ADD_USER,
  FIND_USER,
  GET_ALL_ROLES,
  GET_PAGE_USER,
  UPDATE_PAGE_NUM,
  UPDATE_PAGE_SIZE
} from '@/store/user/CONST'
import { addUserObj, userArr, userState } from '@/store/user/userIntetFace'
import { addUser } from '@/api/user'
import { log } from 'echarts/types/src/util/log'

export default {
  [ADD_USER] (state: userArr, user: addUserObj) {
    addUser(user).then((res) => {
      console.log(res)
    })
  },

  [GET_PAGE_USER] (state: userState, data: { total:0, users: userArr }) {
    state.userArr = data.users
    state.count = data.total
  },

  [FIND_USER] (state:userState, name:string) {
    const newArr = state.userArr.filter(item => item.username.includes(name))
    state.userArr = newArr
  },

  [UPDATE_PAGE_SIZE] (state:userState, num:number) {
    state.pageSize = num
  },

  [UPDATE_PAGE_NUM] (state:userState, num:number) {
    state.pageNum = num
  },

  [GET_ALL_ROLES] (state:userState, arr:Array<object>) {
    state.roles = arr
  }
}
